package o;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse.TabInfo;
import java.util.ArrayList;
import java.util.List;
import o.ewm.h;
import o.ewm.j;

public class ejh extends androidx.recyclerview.widget.RecyclerView.a<s> {
    private GridLayoutManager ʽ;
    private boolean ˊ;
    private ArrayList<TabInfo> ˋ;
    private c ˎ;
    private e ˏ;
    private Context ॱ;

    public interface d {
        void ˊ();

        void ˋ();

        void ˎ();
    }

    public interface c {
        void ˊ(s sVar);
    }

    public interface e {
        void ˊ(TabInfo tabInfo, int i);
    }

    class a implements OnTouchListener {
        final /* synthetic */ ejh ˊ;
        private b ˏ;

        public a(ejh o_ejh, b bVar) {
            this.ˊ = o_ejh;
            this.ˏ = bVar;
        }

        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (!this.ˏ.ʻॱ) {
                Logger.ˏ("EditSubTabAdapter", "onTouch false");
            } else if (motionEvent.getAction() == 0) {
                this.ˊ.ˊ(this.ˏ);
            }
            return false;
        }
    }

    public class b extends s {
        boolean ʻॱ;
        final /* synthetic */ ejh ʼॱ;
        ImageView ॱˋ;
        LinearLayout ॱᐝ;
        TextView ᐝॱ;

        public b(ejh o_ejh, View view) {
            this.ʼॱ = o_ejh;
            super(view);
            this.ॱˋ = (ImageView) view.findViewById(j.ʽꓸ);
            this.ᐝॱ = (TextView) view.findViewById(j.ˊﾞ);
            this.ॱᐝ = (LinearLayout) view.findViewById(j.ʾꞌ);
        }
    }

    public ejh(Context context, GridLayoutManager gridLayoutManager, boolean z) {
        this.ॱ = context;
        this.ʽ = gridLayoutManager;
        this.ˊ = z;
    }

    public long ˏ(int i) {
        if (!CollectCheck.isEmpty(this.ˋ) && this.ˋ.size() > i) {
            TabInfo tabInfo = (TabInfo) this.ˋ.get(i);
            if (tabInfo != null) {
                return (long) tabInfo.hashCode();
            }
        }
        return (long) i;
    }

    @NonNull
    public s ˎ(@NonNull ViewGroup viewGroup, int i) {
        return new b(this, LayoutInflater.from(viewGroup.getContext()).inflate(h.ॱᐨ, viewGroup, false));
    }

    public void ˋ(@NonNull s sVar, int i, @NonNull List<Object> list) {
        super.ˋ(sVar, i, list);
    }

    public void ॱ(@NonNull s sVar, int i) {
        TabInfo tabInfo = (TabInfo) this.ˋ.get(i);
        b bVar = (b) sVar;
        bVar.ʻॱ = tabInfo.ˎ() == 0;
        bVar.ᐝॱ.setText(tabInfo.ᐝ());
        bVar.ॱᐝ.getLayoutParams().width = ᐝ();
        String ॱ = tabInfo.ॱ();
        if (!TextUtils.isEmpty(ॱ)) {
            if (!(bVar.ॱˋ.getTag() instanceof String)) {
                bVar.ॱˋ.setTag(ॱ);
                equ.ˊ(bVar.ॱˋ, ॱ, "img_bg_icon");
            } else if (!ॱ.equals((String) bVar.ॱˋ.getTag())) {
                bVar.ॱˋ.setTag(ॱ);
                equ.ˊ(bVar.ॱˋ, ॱ, "img_bg_icon");
            }
        }
        if (this.ˊ) {
            ॱ(bVar);
        } else {
            ˏ(bVar);
        }
        ˋ(sVar, tabInfo, bVar);
        ˎ(bVar);
        ˎ(bVar, tabInfo, i);
    }

    private void ˎ(b bVar, final TabInfo tabInfo, final int i) {
        OnClickListener anonymousClass3 = new OnClickListener(this) {
            final /* synthetic */ ejh ˏ;

            public void onClick(View view) {
                if (this.ˏ.ˏ != null && !this.ˏ.ˊ) {
                    this.ˏ.ˏ.ˊ(tabInfo, i);
                }
            }
        };
        bVar.ॱᐝ.setOnClickListener(anonymousClass3);
        bVar.ॱˋ.setOnClickListener(anonymousClass3);
        bVar.ᐝॱ.setOnClickListener(anonymousClass3);
    }

    private void ˎ(b bVar) {
        OnTouchListener aVar = new a(this, bVar);
        bVar.ॱᐝ.setOnTouchListener(aVar);
        bVar.ॱˋ.setOnTouchListener(aVar);
        bVar.ᐝॱ.setOnTouchListener(aVar);
    }

    private void ˋ(@NonNull final s sVar, final TabInfo tabInfo, final b bVar) {
        OnLongClickListener anonymousClass2 = new OnLongClickListener(this) {
            final /* synthetic */ ejh ॱ;

            public boolean onLongClick(View view) {
                this.ॱ.ˎ(tabInfo, bVar, sVar.ˋ());
                return true;
            }
        };
        bVar.ॱᐝ.setOnLongClickListener(anonymousClass2);
        bVar.ॱˋ.setOnLongClickListener(anonymousClass2);
        bVar.ᐝॱ.setOnLongClickListener(anonymousClass2);
    }

    private void ˊ(b bVar) {
        if (this.ˎ != null && this.ˊ) {
            Logger.ˏ("EditSubTabAdapter", "MotionEvent.ACTION_DOWN, startDrag");
            this.ˎ.ˊ(bVar);
        }
    }

    private int ᐝ() {
        int ˎ = this.ʽ.ˎ();
        return (int) (((float) (azb.ॱ(this.ॱ) - (this.ॱ.getResources().getDimensionPixelSize(o.ewm.d.ॱˊ) * (ˎ + 1)))) / Float.parseFloat(ˎ + ""));
    }

    public int ˏ() {
        if (this.ˋ != null) {
            return this.ˋ.size();
        }
        return 0;
    }

    public void ˎ(ArrayList<TabInfo> arrayList) {
        this.ˋ = arrayList;
    }

    public void ˎ(c cVar) {
        this.ˎ = cVar;
    }

    private void ˎ(TabInfo tabInfo, b bVar, int i) {
        if (this.ˊ) {
            Logger.ˎ("EditSubTabAdapter", "handleLongClick: isEditing state, stop handle long click.");
            return;
        }
        this.ˊ = true;
        if (this.ॱ instanceof d) {
            ((d) this.ॱ).ˎ();
        }
        ॱ(0, i);
        ॱ(i + 1, (this.ˋ.size() - i) - 1);
        if (tabInfo.ˎ() == 1) {
            Logger.ˎ("EditSubTabAdapter", "Current channel is fixed, so start edit mode only.");
        } else if (this.ˎ != null) {
            if (Logger.ˎ()) {
                Logger.ˏ("ChannelMangager", "MotionEvent.ACTION_DOWN, startDrag");
            }
            this.ˎ.ˊ(bVar);
        }
    }

    private void ˏ(b bVar) {
        bVar.ॱᐝ.setBackground(null);
    }

    private void ॱ(b bVar) {
        if (bVar.ʻॱ) {
            bVar.ॱᐝ.setBackgroundResource(o.ewm.e.ॱᐝ);
        } else {
            bVar.ॱᐝ.setBackground(null);
        }
    }

    public void ˏ(boolean z) {
        this.ˊ = z;
        ˊ();
    }

    public void ˏ(e eVar) {
        this.ˏ = eVar;
    }

    protected void ॱ() {
        if (this.ॱ instanceof d) {
            ((d) this.ॱ).ˊ();
        }
    }

    protected void ʻ() {
        if (this.ॱ instanceof d) {
            ((d) this.ॱ).ˋ();
        }
    }
}
